package 笔试.携程;

import java.util.*;

/**
 * @author:谢君臣
 * @Date:2021/6/10-18:58
 * @version:1.0
 * @function:
 */
public class xc04 {
    public static void main(String[] args) {
        Scanner scanner  = new Scanner(System.in);
        String[] line1 = scanner.nextLine().split(" ");
        int n = Integer.parseInt(line1[0]);
        int m = Integer.parseInt(line1[1]);
        String[] s = scanner.nextLine().split("0");
        HashMap<Integer,Integer> rule = new HashMap<>();
        int [] key = new int[n];
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            String[] temp = scanner.nextLine().split(" ");
            rule.put(Integer.parseInt(temp[0]),Integer.parseInt(temp[1]));
            min = Math.min(min,Integer.parseInt(temp[0]));
            key[i] = Integer.parseInt(temp[0]);
        }
        int [] dp = new int[n+1];
        Arrays.sort(key);
        for (int i = 1; i <= n; i++) {
            while (!rule.containsKey(i)&&i<min)dp[i++]=0;
            dp[i] = fun(dp,rule,i,key);
        }
        int score = 0;
        for (String s1 : s)
            score+=dp[s1.length()];
        System.out.println(score);
    }

    private static int fun(int[] dp, HashMap<Integer, Integer> rule, int i, int[] key) {
        int temp = rule.getOrDefault(i,0); // 获取默认规则得分
        for (int j = 0; j < i; j++) {
                temp = Math.max(dp[j]+dp[i-j],temp);
        }
        return temp;
    }
}
